package by.dezhits.makeanote.adapter;

import android.content.Context;
import android.database.Cursor;
import android.support.v4.widget.CursorAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import by.dezhits.makeanote.R;
import by.dezhits.makeanote.content.contract.FoldersContract;

public class FoldersCursorAdapter extends CursorAdapter {

	public FoldersCursorAdapter(Context context, Cursor c) {
		super(context, c, true);
	}

	@Override
	public void bindView(View oldView, Context context, Cursor cursor) {
		TextView tvName = (TextView) oldView.findViewById(R.id.tv_folder_name);
		ImageView iv = (ImageView) oldView.findViewById(R.id.iv_adapter_folder);
		String name = cursor.getString(cursor
				.getColumnIndex(FoldersContract.FoldersColumns.NAME));
		String pass = cursor.getString(cursor
				.getColumnIndex(FoldersContract.FoldersColumns.PASS));
		tvName.setText(name);
		if (pass != null) {
			iv.setBackgroundResource(android.R.drawable.alert_dark_frame);
		} else {
			iv.setBackgroundResource(android.R.drawable.alert_light_frame);
		}
	}

	@Override
	public View newView(Context context, Cursor cursor, ViewGroup viewGroup) {
		View view = View.inflate(context, R.layout.adapter_folder, null);
		return view;
	}

}
